package com.ems.service.impl;

import com.ems.entity.TMachine;
import com.ems.entity.TPressureCurve;
import com.ems.entity.TTemperatureCurve;
import com.ems.mapper.TMachineMapper;
import com.ems.service.ITMachineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CSC
 * @since 2022-06-28
 */
@Service
public class TMachineServiceImpl extends ServiceImpl<TMachineMapper, TMachine> implements ITMachineService {
    @Autowired
    TMachineMapper tMachineMapper;
    @Override
    public int addMachine(TMachine tMachine) {
        return tMachineMapper.insert(tMachine);
    }

    @Override
    public int deleteMachine(Integer id) {
        return tMachineMapper.deleteById(id);
    }

    @Override
    public int updateMachine(TMachine tMachine) {
        return tMachineMapper.updateById(tMachine);
    }

    @Override
    public List<TMachine> getListMachine() {
        return tMachineMapper.selectList(null);
    }

    @Override
    public List<TMachine> getStateById(Integer id){return tMachineMapper.getStateById(id);}

    @Override
    public List<TTemperatureCurve> getTempList(){return tMachineMapper.getTempList();}

    @Override
    public List<TPressureCurve> getPressureList(){return tMachineMapper.getPressureList();}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateStatus(Integer id, TMachine tMachine) {
        //确认权限
        int pid = baseMapper.permit(id);
        if(pid == 3){
            baseMapper.updateStatus(tMachine);
        }else{
            return false;
        }
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean repair(Integer id, TMachine tMachine) {
        //确认权限
        int pid = baseMapper.permit(id);
        if(pid == 3){
            baseMapper.repair(tMachine);
        }else{
            return false;
        }
        return true;
    }
}